package com.voicechat.firstmet.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.voicechat.firstmet.R;
import com.voicechat.firstmet.base.BaseAdapter;
import com.voicechat.firstmet.bean.CoummunityNotice;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @ProjectName: FirstMet
 * @Package: com.voicechat.firstmet.adapter
 * @ClassName: NoticeAdapter
 * @Description: 系统公告adapter
 * @Author: ljp
 * @CreateDate: 2018/11/16 16:06
 * @Version: 1.0
 */
public class NoticeAdapter extends BaseAdapter<CoummunityNotice.PageBean.ListBean> {
    private ItemClick itemClick;

    public void setItemClick(ItemClick itemClick) {
        this.itemClick = itemClick;
    }

    /**
     * @param context activity_imessage
     * @param tlist   集合
     * @param mLayout 主布局
     */
    public NoticeAdapter(Context context, List<CoummunityNotice.PageBean.ListBean> tlist, int mLayout) {
        super(context, tlist, mLayout);
    }

    @Override
    protected RecyclerView.ViewHolder getHeaderViewHolder(View view) {
        return null;
    }

    @Override
    protected RecyclerView.ViewHolder getItemViewHolder(View view) {
        return new ItemViewHolder(view);
    }

    @Override
    protected RecyclerView.ViewHolder getFooterViewHolder(View view) {
        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
        if(viewHolder instanceof ItemViewHolder){
            ItemViewHolder itemViewHolder = (ItemViewHolder) viewHolder;
            CoummunityNotice.PageBean.ListBean listBean = tlist.get(position);
            itemViewHolder.tvNoticeTitle.setText(listBean.getTitle());
            itemViewHolder.tvNoticeTime.setText(listBean.getUpdateDate());
            itemViewHolder.linearContent.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    itemClick.itemNoticeClicek(listBean);
                }
            });
        }

    }

    class ItemViewHolder extends BaseViewHolder{
        @BindView(R.id.tv_notice_title)
        TextView tvNoticeTitle;
        @BindView(R.id.tv_notice_time)
        TextView tvNoticeTime;
        @BindView(R.id.linear_content)
        LinearLayout linearContent;
        public ItemViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }

   public interface ItemClick{
        void itemNoticeClicek(CoummunityNotice.PageBean.ListBean listBean);
    }
}
